# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

require 'Vu/Font'
require 'Vu/Gadget'

module Vu
	
	# Text label
	# TODO: left/right display as well as centered
	class Label < Gadget
		attr_reader :text, :font
		
		@cached_text_extents = nil
		
		# Create a label, with text and optional font argument
		def initialize (text, font=Font.new())
			@text = text
			@font = font
		end
		
		def contains? (x,y)
			false
		end
		
		def render (cr)
			cr.set_source_rgb(0,0,0)
			font.set_on_context(cr)
			
			unless @cached_text_extents
				@cached_text_extents = cr.text_extents(text)
			end
			x = width/2 - @cached_text_extents.x_bearing - @cached_text_extents.width/2
			y = height/2 - @cached_text_extents.y_bearing - @cached_text_extents.height/2
			cr.move_to(x,y)
			cr.show_text(text)
		end
	end
end
